package interfaces.hud.pilot;

import interfaces.hud.targetInfos.StaticTargetArrow;
import logic.common.missions.Mission;
import logic.common.player.Player;
import logic.common.player.playerListeners.MissionActivatedEvent;
import logic.common.player.playerListeners.PlayerMissionListener;

public class MissionArrowHandler {
	
	private Player player;
	private StaticTargetArrow missionArrow;
	private Mission lastActiveMission;
	private PilotHUD pilotHUD;
	
	public MissionArrowHandler(Player player, PilotHUD pilotHUD) {
		this.player = player;
		this.pilotHUD = pilotHUD;
		
		missionArrow = new StaticTargetArrow(player.getEnemyTeam().getMotherShip(), pilotHUD);
		pilotHUD.getRootNode().attachChild(missionArrow);
		
		initMissionListener();
	}
	
	private void initMissionListener() {
		pilotHUD.addListener(player, new PlayerMissionListener() {
			@Override
			public void missionActivated(MissionActivatedEvent event) {
				initActiveMission(event.getMission());
			}
		});
		
		if(player.getActiveMission() != null) initActiveMission(player.getActiveMission());
	}
	
	private void initActiveMission(Mission mission) {
		lastActiveMission = mission;
		missionArrow.setLocation(lastActiveMission.getMissionLocation());
	}
}